layui.use(['laydate', 'form', 'table', 'fsoft'], function () {
  var $ = layui.$
    , laydate = layui.laydate
    , form = layui.form
    , table = layui.table
    , fsoft = layui.fsoft;
  var tableId = "table-body";
  var searchFormId = "fsoftSearchForm";
  // 执行一个laydate实例
  laydate.render({ elem: '#start', theme: 'grid', calendar: true });
  // 执行一个laydate实例
  laydate.render({ elem: '#end', theme: 'grid', calendar: true });
  //搜索监听
  form.on('submit(sreach)', function (data) {
    active.doSearch(data.field);
    return false;
  });
  table.on('toolbar(' + tableId + ')', function (obj) {
    var checkStatus = table.checkStatus(obj.config.id);
    switch (obj.event) {
      case 'removeBatch':
        active.removeBatch(checkStatus.data);
        break;
    };
  });
  var active = {
    doSearch: function (params) {
      if (params == undefined || params == null)
        params = $.extend({}, form.val(searchFormId));
      // 第一个实例
      table.render({
        elem: '#' + tableId,
        title: "系统日志列表",
        where: params,
        url: layui.cache['contentPath'] + '/sys/log/findList',
        toolbar: '#batchBtnToolBar',
        defaultToolbar: ['filter'],
        cols: [[
          { type: 'checkbox', fixed: 'left', width: 60 },
          { type: 'numbers', fixed: 'left', title: '序号', width: 60 },
          { field: 'operateName', title: '操作', width: 120, sort: true, align: 'center', style: 'text-align:left;' },
          { field: 'operation', title: '详细描述', minWidth: 300, align: 'center', style: 'text-align:left;' },
          { field: 'createTime', title: '操作时间', width: 160, sort: true, align: 'center', style: 'text-align:right;' },
          { field: 'createUserName', title: '操作人', width: 150, align: 'center', style: 'text-align:left;' }
        ]],
        page: { limit: 20, limits: [20, 30, 50, 80, 100], theme: '#1E9FFF' },
        height: 'full-108'
      });
    }
    , removeBatch: function (data) { // 获取选中数据
      if (data == undefined || data.length == 0) {
        layer.msg("请至少选择一条记录", { icon: 7, time: 3000 });
        return;
      }
      var ids = new Array();
      $.each(data, function (idx, item) {
        ids.push(item.id);
      });
      fsoft.confirm("询 问", "确认要删除已选中的日志记录？", function (index) {
        fsoft.put(layui.cache['contentPath'] + '/sys/log/removeBatch', ids, function (rs) {
          if (rs.code == 0) {
            fsoft.successMsg("删除成功");
            active.doSearch();
          }
          layer.close(index);
        });
      });
    }
  };
  active.doSearch();
});